<?php
class Shop_Model_Index extends Zend_Db_Table
 {
       	protected $_name="shop";
       	protected $_primary = 'id';
        
 		public function insertShop($arrParam = null, $option = null)
	  	{	
	  		$row = $this->fetchNew();		  	
			$row->name       =$arrParam['name'];						
			$row->phone1       =$arrParam['phone1'];
			$row->phone2       =$arrParam['phone2'];
			$row->userid       =$arrParam['userid'];
			$row->address1       =$arrParam['address1'];
			$row->address2       =$arrParam['address2'];
			$row->pageid       =$arrParam['pageid'];
			$row->createdate   = date('Y-m-d h:i:s',time());
			
		  	return $row->save();
	  	}
	  	
 		public function updateShop($arrParam = null, $option = null)
		{
			$db = Zend_Registry::get('connectDB');	
			$where = "id = '".$arrParam['id']."'";

			$data = array();
			
			if (@$arrParam['name'] != ""){
				$data["name"]=$arrParam['name'];
			}
			
			if (@$arrParam['phone1'] != ""){
				$data["phone1"]=$arrParam['phone1'];
			}
			
			if (@$arrParam['userid'] != ""){
				$data["userid"]=$arrParam['userid'];
			}
			
			if (@$arrParam['address1'] != ""){
				$data["address1"]=$arrParam['address1'];
			}
			
			if (@$arrParam['address2'] != ""){
				$data["address2"]=$arrParam['address2'];
			}
			
			if (@$arrParam['pageid'] != ""){
				$data["pageid"]=$arrParam['pageid'];
			}
									
			$db->update("shop", $data, $where);
		}
	  	
 		public function getItemById($idshop){
	
	  		$db = Zend_Registry::get('connectDB');		
			$sql = "SELECT *  FROM shop where id =  '".$idshop."'";
	  		
			return $db->fetchRow($sql);
	  	
	  		
	  	}
	  	
 		public function getItemByPageId($pageid){
	
	  		$db = Zend_Registry::get('connectDB');		
			$sql = "SELECT *  FROM shop where pageid =  '".$pageid."'";
	  		
			return $db->fetchRow($sql);
	  		
	  	}
	  	
	 	public function listItem($arrParam = null, $option = null){
			
			$db = Zend_Registry::get('connectDB');
					
	  		$sql = "select * from shop where userid = '".$arrParam['userid']."'";
	  		$result = $db->fetchAll($sql);
			
	  		return $result;
	  	}
        
 }